package models

import (
	"time"

	"gorm.io/gorm"
)

type User struct {
	ID        uint           `gorm:"primarykey" json:"id,omitempty"`
	CreatedAt time.Time      `json:"created_at,omitempty"`
	UpdatedAt time.Time      `json:"updated_at,omitempty"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`

	Name         string `gorm:"not null" json:"name,omitempty" binding:"required,min=2,max=100"`                 //名字
	Email        string `gorm:"unique;not null" json:"email,omitempty" binding:"required,email"`                 //电子邮件
	Password     string `gorm:"not null" json:"password,omitempty" binding:"required,min=6"`                     //密码
	Role         string `gorm:"not null;default=USER" json:"role,omitempty" binding:"required,oneof=ADMIN USER"` //角色（比如：管理员，普通用户）
	Token        string `json:"token,omitempty"`                                                                 //验证Token
	RefreshToken string `json:"refresh_token,omitempty"`                                                         //刷新令牌

	//用户喜欢的电影类型--没有建立表之间的关系，存储时存储Json
	FavouriteGenres []Genre `gorm:"not null;type:longtext;serializer:json" json:"favourite_genres,omitempty" binding:"min=1,required,dive"`

	// 声明多对多关系--收藏的电影
	CollectMovieList []Movie `json:"collect_movie_list,omitempty" gorm:"many2many:user_movie_collects;foreignKey:ID;joinForeignKey:UserID;References:ID;joinReferences:MovieID;"`

	//声明一对多关系--发表的电影评论
	MovieVeviewList []MovieReview `json:"movie_veview_list,omitempty" gorm:"foreignKey:UserId"`
}

// 用户登陆时需要传递的参数
type UserLogin struct {
	Email    string `json:"email" binding:"required,email"`
	Password string `json:"password" binding:"required,min=6"`
}

// 响应给前端的用户信息
type UserResponse struct {
	UserId          uint    `json:"user_id"`
	Name            string  `json:"name"`
	Email           string  `json:"email"`
	Role            string  `json:"role"`
	Token           string  `json:"token"`
	RefreshToken    string  `json:"refresh_token"`
	FavouriteGenres []Genre `json:"favourite_genres"`
}
